home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_497 / nlcalc / source / ckeys.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  203 lines

  1. /*
  2.  *  CALC      Provides a calculator that opens on the active screen when
  3.  *            you press a specific key sequence.  Otherwise, the program
  4.  *            waits quitely in the background.
  5.  *
  6.  *              Copyright 1989 by Davide P. Cervone.
  7.  *  You may use this code, provided this copyright notice is kept intact.
  8.  */
  9.  
  10. #define INTUITION_PREFERENCES_H         /* don't need 'em */
  11. #include <intuition/intuition.h>
  12.  
  13. #include "cHandler.h"
  14. #include "cKeys.h"
  15.  
  16.  
  17. #define UPWIDTH       24
  18. #define UPHEIGHT      10
  19. #define UPDEPTH       2
  20. #define UPWORDS       2
  21.  
  22. #define DOWNWIDTH       24
  23. #define DOWNHEIGHT      10
  24. #define DOWNDEPTH       2
  25. #define DOWNWORDS       2
  26.  
  27. #define CLOSEWIDTH       21
  28. #define CLOSEHEIGHT      10
  29. #define CLOSEDEPTH       2
  30. #define CLOSEWORDS       2
  31.  
  32. #ifndef NL_DAEMON
  33.  
  34. extern USHORT UpFrontData[UPDEPTH][UPHEIGHT*UPWORDS];
  35. extern USHORT DownBackData[DOWNDEPTH][DOWNHEIGHT*DOWNWORDS];
  36. extern USHORT CloseData[CLOSEDEPTH][CLOSEHEIGHT*CLOSEWORDS];
  37.  
  38. struct Image UpFrontImage =
  39.    {0,0, UPWIDTH,UPHEIGHT,UPDEPTH, &UpFrontData[0][0], 0x03,0x00, NULL};
  40.  
  41. struct Image DownBackImage =
  42.    {0,0, DOWNWIDTH,DOWNHEIGHT,DOWNDEPTH, &DownBackData[0][0], 0x03,0x00, NULL};
  43.  
  44. struct Image CloseImage =
  45.    {0,0, CLOSEWIDTH,CLOSEHEIGHT,CLOSEDEPTH, &CloseData[0][0], 0x03,0x00, NULL};
  46.  
  47. #endif
  48.  
  49.  
  50. #define TOPBOX(w,h)  {0,0, 0,h-1, 1,h-2, 1,0, w-2,0}
  51. #define BOTBOX(w,h)  {w-1,h-1, w-1,0, w-2,1, w-2,h-1, 1,h-1}
  52. #define BUTTONBOX(w,h)  {TOPBOX(w,h),BOTBOX(w,h)}
  53.  
  54.  
  55. static SHORT KeyBox[2][10]  = BUTTONBOX(KEYW,KEYH);
  56. static SHORT LongBox[2][10] = BUTTONBOX(LONGKEYW,LONGKEYH);
  57. static SHORT TallBox[2][10] = BUTTONBOX(TALLKEYW,TALLKEYH);
  58. static SHORT TextBox[2][10] = BUTTONBOX(DISPLAYW,DISPLAYH);
  59. static SHORT KPadBox[2][10] = BUTTONBOX(KPADW,KPADH);
  60. static SHORT FKeyBox[2][10] = BUTTONBOX(FKPDW,FKPDH);
  61. static SHORT MainBox[2][10] = /* can't use BUTTON: too long for preprocessor */
  62.     {TOPBOX(IMAGEW,IMAGEH),
  63.      BOTBOX(IMAGEW,IMAGEH)};
  64. static SHORT RootBox[] = {10,0, 4,6, 1,3, 0,3, 3,6, 9,0, 17,0};
  65. static SHORT DragBox[] = {CLOSEWIDTH+9,0, WINDW-UPWIDTH-DOWNWIDTH-9,0};
  66.  
  67.  
  68. #define NEXTBORDER(id)      NULL
  69.  
  70. #define OUTBUTTON(id,x,y,box)\
  71.    {x,y, LIGHTPEN,0, JAM1, 5, &box[0][0], NEXTBORDER(id)},\
  72.    {x,y, DARKPEN,0,  JAM1, 5, &box[1][0], &CalcBorder[id-1]}
  73. #define INBUTTON(id,x,y,box)\
  74.    {x,y, DARKPEN,0, JAM1, 5, &box[0][0], NEXTBORDER(id)},\
  75.    {x,y, LIGHTPEN,0,  JAM1, 5, &box[1][0], &CalcBorder[id-1]}
  76. #define ROOTBRDR(id,x,y)\
  77.    {x,y, TEXTPEN,0,  JAM1, 7, &RootBox[0], &CalcBorder[BRDR_KEY]}
  78. #define DRAGBRDR(id,box)\
  79.    {0,4, LIGHTPEN,0,JAM1, 2, &box[0], NULL},\
  80.    {0,8, LIGHTPEN,0,JAM1, 2, &box[0], &CalcBorder[id-1]}
  81.  
  82. struct Border CalcBorder[] =
  83. {
  84.    OUTBUTTON (BRDR_KEY,  0,0, KeyBox),
  85.    OUTBUTTON (BRDR_LONG, 0,0, LongBox),
  86.    OUTBUTTON (BRDR_TALL, 0,0, TallBox),
  87.    ROOTBRDR  (BRDR_ROOT, 4,2),
  88.  
  89.       #undef NEXTBORDER
  90.       #define NEXTBORDER(id)    &CalcBorder[id-2]
  91.    DRAGBRDR  (BRDR_DRAG, DragBox),
  92.    INBUTTON  (BRDR_TEXT, DISPX,DISPY, TextBox),
  93.    INBUTTON  (BRDR_KPAD, KPXPOS,KPYPOS, KPadBox),
  94.    INBUTTON  (BRDR_FKEY, FKXPOS,FKYPOS, FKeyBox),
  95.    INBUTTON  (BRDR_DISP, DISPXPOS,DISPYPOS, FKeyBox),
  96.    OUTBUTTON (BRDR_MAIN, 0,TOPH, MainBox)
  97. };
  98.  
  99. static struct Image BgImage = {0,TOPH, IMAGEW,IMAGEH,0, NULL, 0,BACKPEN, NULL};
  100. static struct Image TextImage =
  101.    {LINEW,LINEH, DISPLAYIW,DISPLAYIH,0, NULL, 0,DISPLAYPEN, NULL};
  102.  
  103. static struct TextAttr KeyFont = {"topaz.font",8,0,NULL};
  104.  
  105. char DisplayBuffer[20] = "-0.";
  106.  
  107. #define KEY_TEXT(s,n,x,y)\
  108.    {TEXTPEN,0,JAM1, (x-n*8)/2,(y-8)/2+1, &KeyFont, s, NULL}
  109. #define DISPNAME(s,n,x,y)\
  110.    {DISPTEXTPEN,0,JAM1, x-n*8-2*LINEW,(y-8)/2+1, &KeyFont, s, NULL}
  111. #define KEYNAME(s,n)    KEY_TEXT(s,n,KEYW,KEYH)
  112. #define LONGNAME(s,n)   KEY_TEXT(s,n,LONGKEYW,LONGKEYH)
  113. #define TALLNAME(s,n)   KEY_TEXT(s,n,TALLKEYW,TALLKEYH)
  114.  
  115.  
  116. struct IntuiText KeyText[] =
  117. {
  118.    LONGNAME("0",1),
  119.    KEYNAME("1",1),
  120.    KEYNAME("2",1),
  121.    KEYNAME("3",1),
  122.    KEYNAME("4",1),
  123.    KEYNAME("5",1),
  124.    KEYNAME("6",1),
  125.    KEYNAME("7",1),
  126.    KEYNAME("8",1),
  127.    KEYNAME("9",1),
  128.    KEYNAME(".",1),
  129.    KEYNAME("+",1),
  130.    KEYNAME("-",1),
  131.    KEYNAME("*",1),
  132.    KEYNAME("/",1),
  133.    KEYNAME("(",1),
  134.    KEYNAME(")",1),
  135.    TALLNAME("=",1),
  136.    KEYNAME("+-",2),
  137.    KEYNAME("",0),
  138.    KEYNAME("%",1),
  139.    KEYNAME("C",1),
  140.    DISPNAME(&DisplayBuffer[1],2,DISPLAYW,DISPLAYH),
  141. };
  142.  
  143.  
  144. #define NEXTGADGET(id)  &CalcGadget[id+1]
  145.  
  146. #define KEY(id,x,y,w,h,c,brdr)\
  147.    {NEXTGADGET(id), x,y, w,h, GADGHCOMP, RELVERIFY,\
  148.     BOOLGADGET, (APTR)&CalcBorder[brdr], NULL, &KeyText[id],\
  149.     NULL, NULL, id, (APTR)c}
  150.  
  151. #define DISPLAY(id,c)\
  152.    {NEXTGADGET(id), DISPX,DISPY, DISPLAYW,DISPLAYH, GADGHCOMP|GADGIMAGE,\
  153.     RELVERIFY, BOOLGADGET, (APTR)&TextImage, NULL, &KeyText[id],\
  154.     NULL, NULL, id, (APTR)c}
  155.  
  156. #define BRDRGADGET(id)\
  157.    {NEXTGADGET(id), 0,0, 0,0, GADGHNONE, 0, BOOLGADGET,\
  158.     (APTR)&CalcBorder[BRDR_MAIN], NULL, NULL, NULL, NULL, id, NULL}
  159.  
  160. #define BGGADGET(id)\
  161.    {NULL, 0,0, 0,0, GADGHNONE| GADGIMAGE, 0, BOOLGADGET, (APTR)&BgImage,\
  162.     NULL, NULL, NULL, NULL, id, NULL}
  163.  
  164. #define KPKEY(id,r,c,ch)    KEY(id,KPX(c),KPY(r),KEYW,KEYH,ch,BRDR_KEY)
  165. #define LONGKEY(id,r,c,ch)  KEY(id,KPX(c),KPY(r),LONGKEYW,LONGKEYH,ch,BRDR_LONG)
  166. #define TALLKEY(id,r,c,ch)  KEY(id,KPX(c),KPY(r),TALLKEYW,TALLKEYH,ch,BRDR_TALL)
  167. #define FKEY(id,r,c,ch)     KEY(id,FKX(c),FKY(r),KEYW,KEYH,ch,BRDR_KEY)
  168. #define RKEY(id,r,c,ch)     KEY(id,FKX(c),FKY(r),KEYW,KEYH,ch,BRDR_ROOT)
  169.  
  170.  
  171. struct Gadget CalcGadget[] =
  172. {
  173.    LONGKEY (KEY_0, 4,0, '0'),
  174.    KPKEY   (KEY_1, 3,0, '1'),
  175.    KPKEY   (KEY_2, 3,1, '2'),
  176.    KPKEY   (KEY_3, 3,2, '3'),
  177.    KPKEY   (KEY_4, 2,0, '4'),
  178.    KPKEY   (KEY_5, 2,1, '5'),
  179.    KPKEY   (KEY_6, 2,2, '6'),
  180.    KPKEY   (KEY_7, 1,0, '7'),
  181.    KPKEY   (KEY_8, 1,1, '8'),
  182.    KPKEY   (KEY_9, 1,2, '9'),
  183.  
  184.    KPKEY   (KEY_DOT,    4,2, '.'),
  185.    KPKEY   (KEY_PLUS,   2,3, '+'),
  186.    KPKEY   (KEY_MINUS,  1,3, '-'),
  187.    KPKEY   (KEY_TIMES,  0,3, '*'),
  188.    KPKEY   (KEY_DIVIDE, 0,2, '/'),
  189.    KPKEY   (KEY_LPAREN, 0,0, '('),
  190.    KPKEY   (KEY_RPAREN, 0,1, ')'),
  191.    TALLKEY (KEY_EQUAL,  3,3, '='),
  192.  
  193.    FKEY    (KEY_SIGN,   0,0, '\\'),
  194.    RKEY    (KEY_SQRT,   0,1, '`'),
  195.    FKEY    (KEY_PERCENT,0,2, '%'),
  196.    FKEY    (KEY_CLEAR,  0,3, '\x7F'),
  197.    
  198.    DISPLAY (KEY_DISP,        '\x08'),
  199.    
  200.    BRDRGADGET (GADG_BRDR),
  201.    BGGADGET   (GADG_BCKGRND)
  202. };
  203.